// pages/login/bind/bind.js
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    studentName: "",
    studentNumber: ""
  },
  inputext: function(e) {
    var key = e.target.dataset.key;
    var value = e.detail.value;
    this.setData({
      [key]: value
    });
  },
  submitForm() {
    if (!this.data.studentName || !this.data.studentNumber) return;
    app.api.ajaxSubmit("/node/wx/tools/getStudentByStudentNumber", {
      studentName: this.data.studentName,
      studentNumber: this.data.studentNumber
    }).then(res => {
      if (res.data.error == 10000 && res.data.data) {
        app.globalData.student = res.data.data.student;
        wx.setStorageSync("parentsInfo", res.data.data.parents);
        wx.navigateTo({
          url: "/pages/login/selectIdentity/selectIdentity"
        })
      } else if (res.data.error == -10001) {
        wx.showModal({
          title: '温馨提示',
          content: res.data.message,
          showCancel: false
        })
      } else {
        wx.showToast({
          title: res.data.message,
          duration: 2000,
          icon: "none",
          mask: true
        })
      }

    }).catch(err => {
      wx.showToast({
        title: "服务器开小差",
        duration: 2000,
        icon: "none",
        mask: true
      })
    })

  }

})